SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE Procedure [dbo].[SP_TMDOCU_CLIE_I03]      
/*-------------------------------------------------------*/      
/*---Empresa              : OFISIS S.A.                --*/      
/*---Cliente              : OFISIS                 --*/      
/*---Sistema              : Tesoreria                  --*/      
/*---M÷dulo               : Empresa                    --*/      
/*---Programa             : Grabacion Doc.Clientes     --*/      
/*---                       M¸dulo Tesoreria y Ventas  --*/      
/*---Script               : tcmovi_b.sql               --*/      
/*---Nombre SP            : SP_TMDOCU_CLIE_I03         --*/      
/*---Desarrollado por     : Javier Flores A.           --*/      
/*---Fecha Creaci÷n       : 14/03/2000                 --*/      
/*---Base Datos           : Microsoft Sql Server       --*/      
/*---Versi÷n              : 7.0                        --*/      
/*---Invoca a SP          :                            --*/      
/*-------------------------------------------------------*/      
      
/*-------------------------------------------------------*/      
/*---Modificado 1 por     : Carlos R. Marquez Escobar  --*/      
/*---Fecha Modificaci÷n   : 18/11/2003                 --*/       
/*---Detalle Modificaci÷n : Genera Mov Automaticos EBcos --*/      
/*-------------------------------------------------------*/      
/*-------------------------------------------------------*/    
/*---Modificado 2 por     : Maribel Julca Rodriguez    --*/    
/*---Fecha Modificaci©n   : 21/04/2005                 --*/     
/*---Detalle Modificaci©n : ingreso de los campos CO_USUA_CREA, CO_USUA_MODI  --*/    
/*-------------------------------------------------------*/    
      
/*-------------------------------------------------------*/      
/*---Comentarios      Genera Movimientos Automaticos   --*/      
/*---                 egresos Bancos                --*/      
/*---                                                  --*/      
/*-------------------------------------------------------*/      
/*-------------------------------------------------------*/      
/*--- Drop Proc SP_TMDOCU_CLIE_I03                      --*/      
/*--- Grant all on SP_TMDOCU_CLIE_I03 to public         --*/       
/*--- EXEC SP_TMDOCU_CLIE_I03
EXEC SP_TMDOCU_CLIE_I03 '01','CAPACITA','CHD','000000000000026','C','20510200145','A & F CENTER S.A.C','SOL','065',
'CON','2011-01-19','001','2011-01-19','',2.741,24,
0, 0, 0, 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 'N', 0, 0, 0, 0, '', 0, 0,
'', 0, 0, '', 0, 0, 24, 0,
Null, Null, Null, '',
'', '', '', '',
'', '', '', '','', '',  '', '',
'2011', '01',
'00200040',  '001', '000000000000026',
'CRE', '191-0156640-0-21', 'N'                                --*/      
/*-------------------------------------------------------*/      
 @ISCO_EMPR      TD_VC_002,       
 @ISCO_USUA_MODI TD_VC_008_USUA,      
 @ISCO_TIPO_DOCU TD_VC_003,       
 @ISNU_DOCU_CLIE TD_VC_020,       
 @ISTI_ENTI  TD_VC_001,      
 @ISCO_CLIE      TD_VC_020,      
 @ISNO_CLIE      TD_VC_050,      
 @ISCO_MONE      TD_VC_003,       
 @ISCO_TIPO_OPER TD_VC_003,       
 @ISCO_COND_PAGO TD_VC_003,        
 @IDFE_EMIS      TD_DT_001,       
 @ISCO_UNID_CONC TD_VC_003,       
 @IDFE_VENC      TD_DT_001,      
 @IDFE_PROG_COBR TD_DT_001,      
 @INFA_TIPO_CAMB TD_NU_015_006,       
 @INIM_BRUT_AFEC TD_NU_016_004,      
 @INIM_BRUT_INAF TD_NU_016_004,       
 @INIM_GAFI      TD_NU_016_004,       
 @INIM_MORA      TD_NU_016_004,       
 @INIM_FLET      TD_NU_016_004,      
 @ISST_AFEC_GAFI TD_VC_001,       
 @ISST_AFEC_MORA TD_VC_001,       
 @ISST_AFEC_FLET TD_VC_001,       
 @ISST_DCT1_BRAF TD_VC_001,      
 @ISST_DCT1_BRIN TD_VC_001,       
 @ISST_DCT1_GAFI TD_VC_001,       
 @ISST_DCT1_MORA TD_VC_001,       
 @ISST_DCT1_FLET TD_VC_001,      
 @ISST_DCT2_BRAF TD_VC_001,       
 @ISST_DCT2_BRIN TD_VC_001,       
 @ISST_DCT2_GAFI TD_VC_001,       
 @ISST_DCT2_MORA TD_VC_001,      
 @ISST_DCT2_FLET TD_VC_001,       
 @INPC_DCT1      TD_NU_009_004,       
 @INIM_DCT1      TD_NU_016_004,       
 @INPC_DCT2      TD_NU_009_004,      
 @INIM_DCT2      TD_NU_016_004,        
 @ISCO_IMP1      TD_VC_003,       
 @INPC_IMP1      TD_NU_009_004,       
  
 @INIM_IMP1      TD_NU_016_004,       
 @ISCO_IMP2      TD_VC_003,      
 @INPC_IMP2      TD_NU_009_004,       
 @INIM_IMP2      TD_NU_016_004,       
 @ISCO_IMP3      TD_VC_003,       
 @INPC_IMP3      TD_NU_009_004,       
 @INIM_IMP3      TD_NU_016_004,      
 @INIM_TOTA      TD_NU_016_004,       
 @INIM_PAGA_REND TD_NU_016_004,       
 @ISCO_TIDO_ORIG TD_VC_003,       
 @ISNU_DOCU_ORIG TD_VC_020,      
 @IDFE_DOCU_ORIG TD_DT_001,       
 @ISDE_OBSE      TD_VC_100,       
      
 @ISCO_VEND      TD_VC_020,      
 @ISCO_LIQU      TD_VC_008,      
 @ISTI_FACT      TD_VC_003,      
 @ISCO_CAJA_STPR  TD_VC_008,      
 @ISAA_CAJA_STPR  TD_VC_004,      
 @ISMM_CAJA_STPR  TD_VC_002,      
 @ISNU_COMP_STPR  TD_VC_008,      
 @ISTI_ENTI_STPR  TD_VC_001,       
 @ISCO_ENTI_STPR  TD_VC_020,      
 @ISCO_BANC_STPR  TD_VC_003,       
 @ISCO_TIPO_STPR   TD_VC_003,      
 @ISNU_DOCU_STPR  TD_VC_020,      
      
 @ISAA_BANC_DEST TD_VC_004,      
 @ISMM_BANC_DEST TD_VC_002,      
 @ISNU_ASTO_DEST TD_VC_020,      
      
 @ISCO_UNID_CNTB TD_VC_003,      
 @ISNU_CHEQ_UPDT TD_VC_020,      
      
 @ISCO_BANC_DEST TD_VC_003,      
 @ISNU_CNTA_DEST TD_VC_020,       
 @ISST_ASTO_RESU TD_VC_001  
 As  
Declare       
  @VSTI_CORR_INEG TD_VC_001,      
  @VSCO_TIPO_OPEG TD_VC_003,      
  @VNUL_CORR_EGRE       TD_IN_001,      
  @VNUL_CORR_INEG       TD_IN_001      
      
      
Begin Tran SP_TMDOCU_CLIE_I01      
      
    If Not Exists(Select CO_TIPO_DOCU      
    From   TMDOCU_CLIE       
    Where  CO_EMPR = @ISCO_EMPR      
                  And CO_TIPO_DOCU = @ISCO_TIPO_DOCU      
                  And NU_DOCU_CLIE = @ISNU_DOCU_CLIE )       
       Begin      
         Insert Into TMDOCU_CLIE(      
  CO_EMPR, CO_TIPO_DOCU, NU_DOCU_CLIE, CO_CLIE,      
         CO_MONE, CO_TIPO_OPER, CO_COND_PAGO, FE_EMIS, CO_UNID_CONC,      
         FE_VENC, FE_PROG_COBR, FA_TIPO_CAMB, IM_BRUT_AFEC,      
         IM_BRUT_INAF, IM_GAFI, IM_MORA, IM_FLET,ST_AFEC_GAFI,      
         ST_AFEC_MORA, ST_AFEC_FLET, ST_DCT1_BRAF, ST_DCT1_BRIN,      
         ST_DCT1_GAFI, ST_DCT1_MORA, ST_DCT1_FLET, ST_DCT2_BRAF,      
         ST_DCT2_BRIN, ST_DCT2_GAFI, ST_DCT2_MORA, ST_DCT2_FLET,      
         PC_DCT1, IM_DCT1, PC_DCT2, IM_DCT2,      
         CO_IMP1, PC_IMP1, IM_IMP1, CO_IMP2, PC_IMP2,      
         IM_IMP2, CO_IMP3,PC_IMP3, IM_IMP3, IM_TOTA,      
         IM_PAGA, TI_DOCU_ORIG, NU_DOCU_ORIG, FE_DOCU_ORIG,      
         ST_CONT, NU_ASTO, DE_OBSE,       
         CO_ESTA_DOCU, CO_USUA_CREA,FE_USUA_CREA, CO_USUA_MODI, FE_USUA_MODI, CO_VEND, CO_LIQU, TI_FACT)      
         Values  (  @ISCO_EMPR,  @ISCO_TIPO_DOCU, @ISNU_DOCU_CLIE, @ISCO_CLIE,      
         @ISCO_MONE, @ISCO_TIPO_OPER, @ISCO_COND_PAGO,  @IDFE_EMIS,      
         @ISCO_UNID_CONC, @IDFE_VENC, @IDFE_PROG_COBR, @INFA_TIPO_CAMB, @INIM_BRUT_AFEC,      
         @INIM_BRUT_INAF, @INIM_GAFI, @INIM_MORA, @INIM_FLET,      
         @ISST_AFEC_GAFI, @ISST_AFEC_MORA, @ISST_AFEC_FLET, @ISST_DCT1_BRAF,      
         @ISST_DCT1_BRIN, @ISST_DCT1_GAFI, @ISST_DCT1_MORA, @ISST_DCT1_FLET,      
         @ISST_DCT2_BRAF, @ISST_DCT2_BRIN, @ISST_DCT2_GAFI, @ISST_DCT2_MORA,      
         @ISST_DCT2_FLET, @INPC_DCT1, @INIM_DCT1, @INPC_DCT2,      
         @INIM_DCT2,  @ISCO_IMP1, @INPC_IMP1, @INIM_IMP1, @ISCO_IMP2,      
         @INPC_IMP2, @INIM_IMP2 , @ISCO_IMP3, @INPC_IMP3 , @INIM_IMP3,      
         @INIM_TOTA, @INIM_PAGA_REND, @ISCO_TIDO_ORIG, @ISNU_DOCU_ORIG,      
         @IDFE_DOCU_ORIG, 'N' , @ISNU_ASTO_DEST, @ISDE_OBSE,      
  'ACT', @ISCO_USUA_MODI,GETDATE(), @ISCO_USUA_MODI, GETDATE(), @ISCO_VEND, @ISCO_LIQU, @ISTI_FACT)      
      
         If @@error <> 0      
            Begin      
              Rollback tran      
              Return      
            End          
      
      
 Select @VSTI_CORR_INEG = TI_CORR_INEG,      
  @VSCO_TIPO_OPEG = CO_TIPO_OPEG      
 From TMCNTA_BANC, TMPARA_TESO      
 Where TMCNTA_BANC.CO_EMPR = @ISCO_EMPR      
  And CO_BANC = @ISCO_BANC_DEST      
  And NU_CNTA_BANC = @ISNU_CNTA_DEST      
  And TMCNTA_BANC.CO_EMPR = TMPARA_TESO.CO_EMPR      
      
      
 Select @VNUL_CORR_EGRE = UL_CORR_EGRE,      
  @VNUL_CORR_INEG = UL_CORR_INEG       
 From TMSABA_MENS      
 Where CO_EMPR = @ISCO_EMPR      
  And CO_BANC = @ISCO_BANC_DEST      
  And NU_CNTA_BANC = @ISNU_CNTA_DEST      
  And AA_BNCO = @ISAA_BANC_DEST      
  And MM_BNCO = @ISMM_BANC_DEST      
      
       
 --- Egreso Automatico de Bancos ---      
 Exec SP_TCMOVI_BANC_I01 @ISCO_EMPR,  @ISCO_USUA_MODI,      
 @ISCO_BANC_DEST, @ISNU_CNTA_DEST, @ISAA_BANC_DEST, @ISMM_BANC_DEST, 'E',      
 Null, @IDFE_EMIS, @VSCO_TIPO_OPEG,  Null ,      
 @ISCO_TIPO_DOCU, @ISNU_DOCU_CLIE, @INFA_TIPO_CAMB, 1, @ISNU_CHEQ_UPDT,      
 @INIM_BRUT_INAF, @IDFE_EMIS,  @ISTI_ENTI, @ISCO_CLIE, Null,      
 'N', 'MOV. AUTOMATICO', @VSTI_CORR_INEG , Null ,      
 @VNUL_CORR_EGRE, @VNUL_CORR_INEG, Null, @ISCO_UNID_CNTB, Null,     
 Null, 'N', Null, @ISST_ASTO_RESU, null    
       
      
      End      
    Else      
      Begin      
        Update  TMDOCU_CLIE      
        Set  CO_MONE = @ISCO_MONE,      
  CO_TIPO_OPER = @ISCO_TIPO_OPER,      
  CO_COND_PAGO = @ISCO_COND_PAGO,      
  FE_EMIS = @IDFE_EMIS,      
  FE_VENC = @IDFE_VENC,      
  FE_PROG_COBR = @IDFE_PROG_COBR,      
  FA_TIPO_CAMB = @INFA_TIPO_CAMB,      
  IM_BRUT_AFEC = @INIM_BRUT_AFEC,      
  IM_BRUT_INAF = @INIM_BRUT_INAF,      
  IM_GAFI  = @INIM_GAFI,      
  IM_MORA = @INIM_MORA,      
  IM_FLET =  @INIM_FLET,      
  ST_AFEC_GAFI = @ISST_AFEC_GAFI,      
  ST_AFEC_MORA = @ISST_AFEC_MORA,      
  ST_AFEC_FLET = @ISST_AFEC_FLET,      
  ST_DCT1_BRAF = @ISST_DCT1_BRAF,      
  ST_DCT1_BRIN = @ISST_DCT1_BRIN,      
  ST_DCT1_GAFI = @ISST_DCT1_GAFI,      
  ST_DCT1_MORA = @ISST_DCT1_MORA,      
  ST_DCT1_FLET = @ISST_DCT1_FLET,      
  ST_DCT2_BRAF = @ISST_DCT2_BRAF,      
  ST_DCT2_BRIN = @ISST_DCT2_BRIN,      
  ST_DCT2_GAFI = @ISST_DCT2_GAFI,      
  ST_DCT2_MORA = @ISST_DCT2_MORA,      
  ST_DCT2_FLET = @ISST_DCT2_FLET,      
  PC_DCT1 = @INPC_DCT1,      
  IM_DCT1 = @INIM_DCT1,      
  PC_DCT2 = @INPC_DCT2,      
  IM_DCT2 = @INIM_DCT2,      
  CO_IMP1 = @ISCO_IMP1,      
  PC_IMP1 = @INPC_IMP1,      
  IM_IMP1 = @INIM_IMP1,      
  CO_IMP2 = @ISCO_IMP2,      
  PC_IMP2 = @INPC_IMP2,      
  IM_IMP2 = @INIM_IMP2,      
  CO_IMP3 = @ISCO_IMP3,      
  PC_IMP3 = @INPC_IMP3,      
  IM_IMP3 = @INIM_IMP3,      
  IM_TOTA = @INIM_TOTA,      
  TI_DOCU_ORIG = @ISCO_TIDO_ORIG,      
  NU_DOCU_ORIG = @ISNU_DOCU_ORIG,      
  FE_DOCU_ORIG = @IDFE_DOCU_ORIG,      
  DE_OBSE = RTRIM(@ISDE_OBSE),      
  CO_UNID_CONC  = @ISCO_UNID_CONC,      
  CO_VEND = @ISCO_VEND,      
  CO_LIQU = @ISCO_LIQU,      
  TI_FACT = @ISTI_FACT,      
  CO_USUA_MODI =  @ISCO_USUA_MODI,      
  FE_USUA_MODI  = Getdate()      
 Where   CO_EMPR = @ISCO_EMPR      
         And CO_TIPO_DOCU = @ISCO_TIPO_DOCU      
         And NU_DOCU_CLIE = @ISNU_DOCU_CLIE      
      
        If @@error <> 0      
           Begin      
             Rollback tran      
      Return      
           End          
      
     End       
      
UPDATE TCMOVI_CAJA      
SET  TI_SITU = 'CHD',  
CO_USUA_MODI = @ISCO_USUA_MODI,     
FE_USUA_MODI = GETDATE()        
WHERE  CO_EMPR = @ISCO_EMPR      
 And CO_CAJA = @ISCO_CAJA_STPR      
 And AA_CAJA = @ISAA_CAJA_STPR      
 And MM_CAJA = @ISMM_CAJA_STPR      
 And NU_COMP_CAJA = @ISNU_COMP_STPR      
 And TI_MOVI = 'I'      
 And TI_ENTI = @ISTI_ENTI_STPR      
 And CO_ENTI = @ISCO_ENTI_STPR      
 And CO_BANC_CHEQ = @ISCO_BANC_STPR      
 And CO_TIPO_DOCU = @ISCO_TIPO_STPR      
 And NU_DOCU = @ISNU_DOCU_STPR      
      
        If @@error <> 0      
           Begin      
             Rollback tran      
             Return      
           End      
      
      
      
      
Commit Tran      
      
/*-------------------------- Fin ------------------------------*/  
GO
